<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%--
  Created by IntelliJ IDEA.
  User: zuti666
  Date: 2020/6/23
  Time: 10:28
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>

<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>backend</title>
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/statics/bootstarp/css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/statics/css/index.css" />
    <script src="${pageContext.request.contextPath}/statics/js/jquery.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/statics/bootstarp/js/bootstrap.js" type="text/javascript" charset="utf-8"></script>
    <script src="${pageContext.request.contextPath}/statics/js/userSetting.js" type="text/javascript" charset="utf-8"></script>
    <!-- 引入bootstrap插件 -->
    <script type="text/javascript" src="${pageContext.request.contextPath }/statics/js/bootstrap-paginator.js" charset="utf-8" ></script>
    <script type="text/javascript">
        function UserValue(userId) {
            $("#modifyId").val(userId);
    }



    $(function()
        {
            //
            $("#userName").val("${userParam.userName }");
            $("#loginName").val("${userParam.loginName }");
            $("#phone").val("${userParam.phone }");
            $("#address").val("${userParam.address }");
            $("#isValid").find("option[value='${userParam.isValid }']").attr("selected", true);


            // 修改会员信息
            $("#modifyUserById").click(function()
            {
                $.ajax(
                    {
                        type : "post",
                        url  : "${pageContext.request.contextPath }/user/modifyById",
                        data : {
                            "userId"    : $("#modifyId").val(),
                            "userName"  : $("#modifyUserName").val(),
                            "loginName" : $("#modifyLoginName").val(),
                            "phone"     : $("#modifyPhone").val(),
                            "address"   : $("#modifyAddress").val()
                        },
                        dataType : "json",
                        success  : function(result)
                        {
                            if (result.responseCode == 1)
                            {
                                location.href = "${pageContext.request.contextPath }/user/searchByParamList";
                            }else
                            {
                                $("#errorMsg").tooltip(
                                    {
                                        title     : "error",
                                        placement : "center",
                                        template  : "<div class='tooltip errorMsg'>" + result.message + "</div>",
                                        tigger    : "manual"
                                    }).tooltip("show");
                            }
                        }
                    });
            });

            // 启用/禁用
            $("input[name='modifyStatus']").click(function()
            {
                $.ajax(
                    {
                        type : "post",
                        url  : "${pageContext.request.contextPath }/user/modifyStatus",
                        data : {
                            "id"     : $(this).attr("data-id"),
                            "status" : $(this).attr("data-value")
                        },
                        dataType : "json",
                        success  : function(result)
                        {
                            if (result.responseCode == 1)
                            {
                                location.href = "${pageContext.request.contextPath }/user/searchByParamList";
                            }else
                            {
                                $("#errorMsg").tooltip(
                                    {
                                        title     : "error",
                                        placement : "center",
                                        template  : "<div class='tooltip errorMsg'>" + result.message + "</div>",
                                        tigger    : "manual"
                                    }).tooltip("show");
                            }
                        }
                    });
            });
        });
    </script>
</head>

<body>
<div class="panel panel-default" id="userInfo" id="homeSet">
    <div class="panel-heading">
        <h3 class="panel-title">用户管理</h3>
    </div>
    <div class="panel-body">

        <div class="show-list" style="position: relative;top: 30px;">
            <form class="form-inline" id="searchForm" action="${pageContext.request.contextPath }/user/searchByParamList" method="post" >

                <div class="showusersearch">
                    <!-- 添加
	                       id="searchForm"
	                       action="${pageContext.request.contextPath }/user/findByFuzzyParamList"
	                       method="post"
	                -->
<%--                    <form class="form-inline" id="searchForm" action="${pageContext.request.contextPath }/user/findByFuzzyParamList" method="post" >--%>
                        <div class="form-group">
                            <label >姓名:</label>
                            <!-- 添加   name="userName" -->
                            <input type="text" class="form-control"  id="searchUserName" name="searchUserName" placeholder="请输入姓名" value="${UserName}" >
                        </div>
                        <div class="form-group">
                            <label >帐号:</label>
                            <input type="text" class="form-control" id="searchLoginName" name="searchLoginName" placeholder="请输入帐号" value="${LoginName}">
                        </div>
                        <div class="form-group">
                            <label >电话:</label>
                            <input type="text" class="form-control"  id="searchPhone"  name="searchPhone" placeholder="请输入电话" value="${Phone}">
                        </div>
                        <div class="form-group">
                            <label >地址:</label>
                            <input type="text" class="form-control"  id="searchAddress"  name="searchAddress" placeholder="请输入地址" value="${Address}">
                        </div>
                        <div class="form-group">
                            <label >状态</label>


                            <select class="form-control" id="searchIsValid" name="searchIsValid">
                                <option value="-1">全部</option>
                                <option value="1">---有效---</option>
                                <option value="0">---无效---</option>
                            </select>
                        </div>
                        <input type="submit" value="查询" class="btn btn-primary" id="doSearch">
                </div>
                <input type="hidden" name="pageIndex" value="1"/>
            </form>


            <table class="table table-bordered table-hover" style='text-align: center;'>
                <thead>
                <tr class="text-danger">
                    <th class="text-center">用户ID</th>
                    <th class="text-center">姓名</th>
                    <th class="text-center">帐号</th>
                    <th class="text-center">电话</th>
                    <th class="text-center">地址</th>
                    <th class="text-center">状态</th>
                    <th class="text-center">操作</th>
                </tr>
                </thead>
                <tbody id="tb">
                <c:forEach var="user" items="${UserList}"  >
                    <tr>
                        <td>${user.userId}</td>
                        <td>${user.userName}</td>
                        <td>${user.loginName}</td>
                        <td>${user.phone}</td>
                        <td>${user.address}</td>
                        <td>
                            <c:if test="${user.isValid eq 1 }">有效</c:if>
                            <c:if test="${user.isValid eq 0 }">无效</c:if>
                        </td>
                        <td class="text-center">
                            <input type="button" class="btn btn-warning btn-sm doModify" value="修改" name="toModifyUser" data-value="${user.userId}"
                                   data-target="#myModal" onclick="UserValue('${user.userId}')">
                            <c:if test="${user.isValid eq 1 }">
                                <input type="button" class="btn btn-danger btn-sm doDisable" value="禁用" name="modifyStatus" data-id="${user.userId}" data-value="${user.isValid }">
                            </c:if>
                            <c:if test="${user.isValid eq 0 }">
                                <input type="button" class="btn btn-danger btn-sm doDisable" value="启用" name="modifyStatus" data-id="${user.userId }" data-value="${user.isValid }">
                            </c:if>
                        </td>
                    </tr>
                </c:forEach>
                </tbody>
            </table>
                <input type="hidden" id="totalPageCount" value="${pageSupport.totalPageCount}"/>
                <c:import url="../rollpage.jsp">
                    <c:param name="totalCount" value="${pageSupport.totalCount}"/>
                    <c:param name="currentPageNo" value="${pageSupport.currentPageNo}"/>
                    <c:param name="totalPageCount" value="${pageSupport.totalPageCount}"/>
                </c:import>

                <!-- 添加 ul -->
<%--                <ul id="userPage"></ul>--%>

        </div>

        <div class="modal fade" tabindex="-1" id="myModal">
            <!-- 窗口声明 -->
            <div class="modal-dialog modal-lg">
                <!-- 内容声明 -->
                <div class="modal-content">
                    <!-- 头部、主体、脚注 -->
                    <div class="modal-header">
                        <button class="close" data-dismiss="modal">&times;</button>
                        <h4 class="modal-title">用户修改</h4>
                    </div>
                    <div class="modal-body text-center">
                        <div class="row text-right">
                            <label  class="col-sm-4 control-label">编号：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="modifyId"  name="modifyId" readonly >
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label class="col-sm-4 control-label">姓名：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="modifyUserName"  name="modifyUserName">
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label class="col-sm-4 control-label">帐号：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="modifyLoginName" name="modifyLoginName">
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label  class="col-sm-4 control-label">电话：</label>
                            <div class="col-sm-4">
                                <input type="text" class="form-control" id="modifyPhone" name="modifyPhone">
                            </div>
                        </div>
                        <br>
                        <div class="row text-right">
                            <label class="col-sm-4 control-label">地址：</label>
                            <div class="col-sm-4">
                                <input type="email" class="form-control" id="modifyAddress">
                            </div>
                        </div>
                        <br>
                    </div>
                    <div class="modal-footer">
                        <button class="btn btn-warning updateOne" id="modifyUserById">修改</button>
                        <button class="btn btn-primary cancel" data-dismiss="modal">取消</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>

</html>